﻿using Microsoft.UI.Xaml.Input;
using Windows.System;

namespace TableViewTest.Pages
{
    [Menu("单元格事件")]
    public sealed partial class CellEventPage : Page
    {
        public TestViewModel ViewModel { get; } = new();
        public CellEventPage() => InitializeComponent();
        private void TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (sender is not TextBlock textBlock || textBlock.Tag is not UserViewModel user) return;
            user.AgeAddOne();
        }
        private void TextBlock_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
        {
            if (sender is not TextBlock textBlock || textBlock.Tag is not UserViewModel user) return;
            user.AgeMinusOne();
        }
        private void StackPanel_KeyDown(object sender, KeyRoutedEventArgs e)
        {
            if (sender is not StackPanel stackPanel || stackPanel.Tag is not UserViewModel user) return;
            if (e.Key == VirtualKey.Enter || e.Key == VirtualKey.Add)
            {
                user.AgeAddOne();
                e.Handled = true;
            }
            else if (e.Key == VirtualKey.Back || e.Key == VirtualKey.Subtract)
            {
                user.AgeMinusOne();
                e.Handled = true;
            }
        }
    }
}
